$(function(){
    var key = getGetUrlParam(location.href).key;
    var baseStr;
    var listContent = $("#list-content");
    $("#selectFileBtn").click(function(){
        var file = fileUtil.selectFile();
        if(file){
            if(file.length > 5242880){
                new MessageBody('错误',"文件不可以大于5M！",1000).showMessage();
                return;
            }
            baseStr = base64Util.toBase64(file.path);
            var bg = "";
            var uFileName = file.fileName.toLocaleLowerCase();
            if(uFileName.endsWith(".png") ||
                uFileName.endsWith(".jpg")||
                uFileName.endsWith(".gif")){
                var bgSize = "";
                try{
                    var imageSize = imageUtil.getImageSize(file.path);
                    bgSize = imageSize[0]+"px "+imageSize[1]+"px";
                }catch (e) {
                }

                bg =  "style='background-image:url("+file.absolutePath+");'";
            }
            if(listContent.children().length >= 3){
                listContent.children().eq(2).remove();
            }
            listContent.prepend("<li><div class='ico-content' "+bg+"></div><span>"+file.fileName+"</span></li>");
            new MessageBody('信息','成功生成base64!文件大小：'+fileUtil.formatFileSize(file.length),10000).showMessage();
        }
    });
    $("#copyBtn").click(function(){
        if(!baseStr || baseStr.length === 0){
            new MessageBody('错误','请先生成base64',1000).showMessage();
            e.preventDefault()
            return;
        }
        clipBoard.setText(baseStr);
        new MessageBody('信息','复制完成！',1000).showMessage();
    });
})